﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ComeSeeThis_MVC2.Models.Company>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Company Details
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.RenderPartial("SubMenu"); %>
    <h2>
        Company Details</h2>
    <fieldset>
        <legend>
            <%: Model.CompanyName %></legend>
        <table width="100%">
            <tr>
                <th colspan="1" width="33%">
                    Company Information
                </th>
                <th width="33%">
                    Vehicles
                </th>
                <th width="33%">
                    Motors
                </th>
            </tr>
            <tr>
                <td valign="top">
                    <% if (Model.CompanyAddresses.Count == 0)
                       {
                           Response.Write("We have no contact information for " + Model.CompanyName);
                       }
                       else
                       {
                           foreach (var address in Model.CompanyAddresses)
                           {
                               if (!string.IsNullOrEmpty(address.Address1))
                                   Response.Write(Html.Encode(address.Address1) + "<br />");
                               if (!string.IsNullOrEmpty(address.Address2))
                                   Response.Write(Html.Encode(address.Address2) + "<br />");
                               if (!string.IsNullOrEmpty(address.Address3))
                                   Response.Write(Html.Encode(address.Address3) + "<br />");
                               if (!string.IsNullOrEmpty(address.City))
                                   Response.Write(Html.Encode(address.City) + ", ");
                               if (!string.IsNullOrEmpty(address.StateProvince))
                                   Response.Write(Html.Encode(address.StateProvince) + "<br />");
                               if (!string.IsNullOrEmpty(address.Country))
                                   Response.Write(Html.Encode(address.Country) + "<br />");
                               if (!string.IsNullOrEmpty(address.ZipPostalCode))
                                   Response.Write(Html.Encode(address.ZipPostalCode) + "<br />");
                               if (!string.IsNullOrEmpty(address.Email))
                               {
                    %>
                    <a href='mailto://<%=Html.Encode(address.Email)%>'>
                        <%=Html.Encode(address.Email)%></a><br />
                    <% }
                               if (!string.IsNullOrEmpty(address.Phone))
                                   Response.Write(Html.Encode(address.Phone) + "<br />");
                               if (!string.IsNullOrEmpty(address.Fax))
                                   Response.Write(Html.Encode(address.Fax) + "<br />");
                               if (!string.IsNullOrEmpty(address.WebSite))
                               {%>
                    <a target="_new" href='http://<%=Html.Encode(address.WebSite)%>'>
                        <%=Html.Encode(address.WebSite)%></a>
                    <br />
                    <%
                        }
                               Response.Write("<br/>");
                           }
                       }%>
                </td>
                <td rowspan="2" valign="top">
                    <% 
                        if (Model.Vehicles.Count > 0)
                        {
                            Html.RenderPartial("CompanyVehicles", Model.Vehicles);
                        }
                        else
                        {
                            Response.Write("No vehicles are currently associated with " + Model.CompanyName + ".");
                        }
                        
                    %>
                </td>
                <td rowspan="2" valign="top">
                    <% 
                        if (Model.Motors.Count > 0)
                        {
                            Html.RenderPartial("CompanyMotors", Model.Motors);
                        }
                        else
                        {
                            Response.Write("No motors are currently associated with " + Model.CompanyName + ".");
                        }
                        
                    %>
                </td>
            </tr>
        </table>
        <p>
            <% if (User.IsInRole("SiteAdmin"))
               { %>
            <%: Html.ActionLink("Edit", "Edit", new { id=Model.CompanyId }) %>
            |
            <%: Html.ActionLink("Delete", "Delete", new { id = Model.CompanyId })%>
            <% }%>
        </p>
    </fieldset>
</asp:Content>
